<template>
  <div class="app-container">
    <customToolbar />
    <!-- <div class="filter-container">
      <div class="filter-item">
        <span class="span">名称 </span>
        <el-input v-model="listQuery.dataProcessName" placeholder="请输入数据处理名称" style="width: 200px" />
      </div>

      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        {{ $t('table.search') }}
      </el-button>
      <el-button v-waves v-permission="['datagovernance:DataGovernance:add']" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">
        {{ $t('table.add') }}
      </el-button>
      <el-button v-waves v-permission="['datagovernance:DataGovernance:delete']" class="filter-item" style="margin-left: 10px;" type="danger" icon="el-icon-delete" @click="handleBathDelete">
        {{ $t('table.delete') }}
      </el-button>
    </div>

    <el-table
      ref="table"
      :key="tableKey"
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      @selection-change="handleSelectionChange"
    >

      
      <el-table-column type="index" align="center" label="序号" width="100" />
      <el-table-column label="名称" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.dataProcessName }}</span>
        </template>
      </el-table-column>

      <el-table-column label="执行类型" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.executeType | dictLabel('executor_type') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="状态" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.status | dictLabel('is_use') }}</span>
        </template>
      </el-table-column>

      <el-table-column label="创建时间" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.createDate }}</span>
        </template>
      </el-table-column>

      <el-table-column label="描述" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.description }}</span>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="center" min-width="180" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button v-permission="['datagovernance:DataGovernance:update']" type="text" size="small" icon="el-icon-edit" @click="handleUpdate(row)">
            {{ $t('table.edit') }}
          </el-button>
          <el-button v-permission="['datagovernance:DataGovernance:delete']" type="text" size="small" icon="el-icon-delete" class="delete-text-btn" @click="handleDelete(row)">
            {{ $t('table.delete') }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageArray" @pagination="getList" />

    <data-governance-form ref="form" @refreshList="getList" /> -->

  </div>
</template>

<script>
import { deleteDataGovernance, fetchDataGovernanceList } from '@/api/datagovernance/dataGovernance'
import waves from '@/directive/waves' // waves directive
import permission from '@/directive/permission/permission'
import dataGovernanceForm from './dataGovernanceForm'
import Pagination from '@/components/Pagination'
import customToolbar from '../customToolbar/customToolbar.vue'
import { mxGraph } from 'mxgraph-js'
export default {
  name: 'DataGovernanceList',
  components: { dataGovernanceForm, Pagination ,customToolbar},
  directives: { waves, permission },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      multipleSelection: [],
      listLoading: false,
      pageArray: this.$store.getters.pageArray,
      listQuery: {
        dataProcessName: undefined,
        status: undefined,
        page: 1,
        limit: this.$store.getters.defaultPageSize
      }
    }
  },
  computed: {
    ids() {
      const ids = []
      this.multipleSelection.forEach(ele => {
        ids.push(ele.id)
      })
      return ids.join(',')
    }
  },
  created() {
    this.getList()
  },
  mounted(){
    // 创建画布
    var graph = new mxGraph(this.$refs.graph_container);
    var parent = graph.getDefaultParent();
    // 开始更新画布
    graph.getModel().beginUpdate();
    try {
      // 插入节点
      let v1 = graph.insertVertex(parent, null, 'Hello,', 20, 20, 80, 30);
      let v2 = graph.insertVertex(parent, null, 'World!', 200, 150, 80, 30);
      // 插入连线
      graph.insertEdge(parent, null, '', v1, v2);
    } finally {
      // 画布更新结束
      graph.getModel().endUpdate();
    }

  },
  methods: {
    getList() {
      // this.listLoading = true
      fetchDataGovernanceList(this.listQuery).then(response => {
        this.list = response.data.data
        this.total = response.data.total
        // this.listLoading = false
      })
    },
    handleCreate() {
      this.$refs.form.handleCreate()
    },
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row.id)
    },
    handleDelete(row) {
      this.$confirm('确定删除该数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteDataGovernance(row.id).then(response => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    handleBathDelete() {
      if (this.ids === '') {
        this.$message.warning('请选择至少一条数据')
        return
      }
      this.$confirm('确定删除所选数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteDataGovernance(this.ids).then(response => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    }

  }
}
</script>
<style >
.span{
  color: #606266;font-weight: 700;font-size: 14px;
}
@import '~bpmn-js/dist/assets/diagram-js.css';
  @import '~bpmn-js/dist/assets/bpmn-font/css/bpmn.css';
  @import '~bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css';
  @import '~bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';
  .containers{
    position: absolute;
    background-color: #ffffff;
    width: 100%;
    height: 100%;
    .canvas{
      width: 100%;
      height: 100%;
    }
    .bjs-powered-by {
      display: none;
    }
  }

</style>../customToolbar/customToolbar.vue